home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11551 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.9 KB  |  145 lines

  1. Path: fido.asd.sgi.com!news
  2. From: Emmanuel Mogenet <mgix@aw.sgi.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Shortcomings ?
  5. Date: Fri, 15 Mar 1996 01:48:10 -0800
  6. Organization: Alias Wavefront
  7. Message-ID: <31493CDA.41C6@aw.sgi.com>
  8. References: <31488E8D.167E@aw.sgi.com> <4iaqch$moh@B1FF.mindspring.com>
  9. NNTP-Posting-Host: fddi-sgigate.sgi.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; IRIX 5.3 IP22)
  14.  
  15. Justin Rudd wrote:
  16. > Emmanuel Mogenet <mgix@aw.sgi.com> wrote:
  17. > >In other word, make portions of the interface to a class private to
  18. > >only some classes.
  19. > >        1. Wouldn't that be nicer than the friend mechanism that cracks
  20. > >           open a class a spill its guts ?
  21. > >        2. Is there a clean way to achieve in today's C++ standard ?
  22. > >        3. Or is it a bad idea altogether ?
  23. > I'm not sure what you mean by this...You want to have a function
  24. > SomeMethodOnlyCallableByManagerForClassA();  That can be called like
  25. > this:
  26. > ManagerForClassA manage;
  27. > manage.SomeMethodOnlyCallableByManagerForClassA();
  28. > hm...OH WAIT...I get it....
  29. > even though ManagerForClassA has no idea what it has inside it should
  30. > still be able to call a member function of A.
  31. > Well this could be simulate using inheritance.  Hm...I've never really
  32. > thought about this...let me get back to you on this one.
  33.  
  34. No.
  35.  
  36. I guess my post was messy and unclear.
  37. What I want is to be able for a class A to tell:
  38.  
  39.  
  40. class A
  41. {
  42. restricted B:
  43.     void    DoSomething();
  44. }
  45.  
  46. This means: Ok, the method A::DoSomething is public, but not
  47. public for everybody. Only members of class B can have access to
  48. this method.
  49.  
  50. It's a bit like the friend operator, but instead of spilling
  51. everything to the friend, we just let him peep through a specialized window.
  52.  
  53. > >2. Pointer type manipulation
  54. > >-----------------------------
  55. > >A very disappointing thing in C++ (unless I am mistaken and it is actually
  56. > >possible to do so) is the following situation:
  57. > >If A is a class, then most operations on A can be redefined.
  58. > >Because A is a full blown type.
  59. > >Sadly, the same can not be said about A* (type: pointer to A).
  60. > >Even though A* is a type, none of its default manipulations
  61. > >can be redefined.
  62. > >Example: You can tell C++, that you want to gain control of the
  63. > >situation whenever an object of type A is duplicated.
  64. > >You do so by redefining the default copy constructor and the default
  65. > >assignment operator.
  66. > >But can you tell C++ that you want to gain control whenever a pointer of
  67. > >A* is duplicated ? Why can't I redefine the copy constructor for the type A* ?
  68. > >In my way of looking at thing, that'd be a *great* way of doing clean reference
  69. > >counting, instead of half-baked method using a redefinition of operator->.
  70. > >Comments ?
  71. > Ok...so you are saying you can do something like this...
  72.  
  73. 8< ... snip snip ... 8<
  74.  
  75. No.
  76.  
  77. What I meant was: I would like to be able to redefine the default
  78. copy constructor for pointers.
  79.  
  80. In other words, when I write:
  81. class A
  82. {
  83. };
  84.  
  85. main()
  86. {
  87.     A    *a;
  88.     B    *b;
  89.  
  90.     a=new A();
  91.     b=a;
  92. }
  93.  
  94. I want the compiler to trap this for me and give me control.
  95. What I really want the compiler to do is:
  96.  
  97. main()
  98. {
  99.     1. Call the constructor of object A* (that's what we do. We build an A*)
  100.     2. Call the constructor of object B*
  101.  
  102.     Call the constructor for object A* (to temporarily store the result of new)
  103.     Call the assignment method (to assign the result of new to a)
  104.     Call the assignment operator (to assign the value of a to b)
  105.     
  106. }
  107.  
  108. Another way to put it:
  109. I would like to be able to write
  110.  
  111. class A*
  112. {
  113.     A*();        // To build a pointer to A
  114.     A*(const A*&)    // To build an A* from another A*
  115.     ~A*();        // To get hold of what happens when a pointer to A goes out of scope
  116.  
  117.     A* operator=(const A*&);    // To redefine assignment
  118.     
  119. }
  120.  
  121.  
  122. All this complicated mechanics would allow to build
  123. industrial-strength reference counting on objects.
  124.  
  125.     - Mgix
  126.